<?php
App::uses('AppController', 'Controller');

class MedicamentospreciosController extends AppController {

/**
 * Helpers
 *
 * @var array
 */
	public $helpers = array('Html', 'Js');

/**
 * Components
 *
 * @var array
 */
public $components = array('Fechasconvert');
/**
 * modelos que usas
 *
 * @var array
 */
public $uses=array('Medicamentosprecio','Medicamento','Seguro');
/**
 * vista el template
 *
 * @var array
 */
public $layout='hospital';
/**
 * funcion de filtro
 *
 * @var array
 */
public function beforeFilter() {
    parent::beforeFilter();
    //$this->Auth->allow();
}
/**
 * index method
 *
 * @return void
 */
	public function index() {
		$this->Medicamentosprecio->recursive = 0;
		$this->set('medicamentosprecios', $this->paginate());
	}

/**
 * view method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function view($id = null) {
		if (!$this->Medicamentosprecio->exists($id)) {
			throw new NotFoundException(__('Invalid Medicamentosprecio'));
		}
		$options = array('conditions' => array('Medicamentosprecio.' . $this->Medicamentosprecio->primaryKey => $id));
		$this->set('medicamentosprecio', $this->Medicamentosprecio->find('first', $options));
	}

/**
 * add method
 *
 * @return void
 */
	public function add() {
		if ($this->request->is('post')) {
			$this->Medicamentosprecio->create();
			if ($this->Medicamentosprecio->save($this->request->data)) {
				$this->Session->setFlash(__('The medicamentosprecio has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The medicamentosprecio could not be saved. Please, try again.'));
			}
		}
		$medicamentos = $this->Medicamentosprecio->Medicamento->find('list', array('fields'=>array('Medicamento.id', 'Medicamento.nombre')));
		$seguros = $this->Medicamentosprecio->Seguro->find('list');
                
		$this->set(compact('medicamentos', 'seguros'));
	}

/**
 * edit method
 *
 * @throws NotFoundException
 * @param string $id
 * @return void
 */
	public function edit($id = null) {
		if (!$this->Medicamentosprecio->exists($id)) {
			throw new NotFoundException(__('Invalid medicamentosprecio'));
		}
		if ($this->request->is('post') || $this->request->is('put')) {
			if ($this->Medicamentosprecio->save($this->request->data)) {
				$this->Session->setFlash(__('The medicamentosprecio has been saved'));
				$this->redirect(array('action' => 'index'));
			} else {
				$this->Session->setFlash(__('The medicamentosprecio could not be saved. Please, try again.'));
			}
		} else {
			$options = array('conditions' => array('Medicamentosprecio.' . $this->Medicamentosprecio->primaryKey => $id));
			$this->request->data = $this->Medicamentosprecio->find('first', $options);
		}
		$medicamentos = $this->Medicamentosprecio->Medicamento->find('list');
		$seguros = $this->Medicamentosprecio->Seguro->find('list');
		$this->set(compact('medicamentos', 'seguros'));
	}

/**
 * delete method
 *
 * @throws NotFoundException
 * @throws MethodNotAllowedException
 * @param string $id
 * @return void
 */
	public function delete($id = null) {
		$this->id = $id;
		if (!$this->Medicamentosprecio->exists()) {
			throw new NotFoundException(__('Invalid medicamentosprecio'));
		}
		$this->request->onlyAllow('post', 'delete');
		if ($this->Medicamentosprecio->delete()) {
			$this->Session->setFlash(__('Medicamentosprecio deleted'));
			$this->redirect(array('action' => 'index'));
		}
		$this->Session->setFlash(__('Medicamentosprecio was not deleted'));
		$this->redirect(array('action' => 'index'));
	}
}
